<template>
   <div id="box">
     <!-- 顶部导航 -->
     <van-nav-bar fixed
      title="搜索"
      left-text="返回"
      right-text="..."
      left-arrow
      @click-left="$router.go(-1)"
    />
        <div class="searchbox">
            <input type="text" v-model="text" placeholder="搜索商家 商品名称">
            <span @click="search()">搜索</span>

        </div>
        <div class="block">
            <div class="title">历史搜索</div><van-icon name="delete-o" @click='del()' class="del"/>
            <div class="list">
                <ul>
                    <li v-for="(item,index) in searchArr" :key="index">{{item}}</li>
                </ul>
            </div>
        </div>
        <div class="block">
            <div class="title find" >搜索发现</div>
            <div class="list findlist" v-for="(item,index) in findArr" :key="index">
                <div class="imgbox">
                <img :src="item.picUrl" alt="">
                </div>
                <div class="name">{{item.name}}</div>
                <div class="sale"> ☆ {{item.wmPoiScore}} {{item.monthSalesTip}}</div>
                <div class="desc">{{item.minPriceTip}} {{item.shippingFeeTip}}</div>
                <!-- <ul>
                    <li v-for="(item,index) in findArr" :key="index">{{item}}</li>
                </ul> -->
            </div>
        </div>

    </div>
</template>

<script>
import {shop_search} from "../utils/api";
export default {
    data(){
        return{
        text:"",//保存输入框输入的内容(临时)
        searchArr:["小龙虾","火锅","自助烧烤","黄焖鸡米饭"],
        findArr:[]
        }
    },
    methods:{
        search(){
            if(this.text!=""){
                this.searchArr.push(this.text);
                
         
            }
            shop_search({ searchkey: this.text }).then((res)=>{
                console.log(res.data.list);
                this.findArr = res.data.list
                this.text="";
            })
        },
        del(){
            this.searchArr.splice(0,this.searchArr.length);
        }
    },
    mounted(){
        // search({keySreach:this.text}).then((res)=>{
        //     console.log(res.data);
        // })
    }
}
</script>

<style lang="scss" scoped>
        *{
            margin: 0;
            padding: 0;
        }
        #box{
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .searchbox{
            margin-top: 60px;
        }
        input {
            background-color: #f1f1f2;
            border: none;
            outline: none;
            width: 240px;
            height: 30px;
            line-height: 30px;
            border-radius: 15px;
            padding-left: 15px;

        }
        .searchbox span{
            display: inline-block;
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            margin-left: 10px;
            color: #00a6ff;
        }
        .block{
            margin-top: 20px;
            
        }
        .block .title{
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 10px;
            display: inline-block;
            
            
        }
        .block .find{
            position: absolute;
            left: 10px;
        }
        .list li{
            display: inline-block;
            height: 30px;
            line-height: 30px;
            background-color: #f1f1f2;
            border-radius: 15px;
            font-size: 15px;
            padding: 0 10px;
            margin-right: 5px;
        }
        .del{
            margin-left: 200px;
            font-size: 20px;
        }
        .imgbox{
      width: 100px;
      margin-right: 10px;
      img{
        width: 90px;
        height: 90px;
      }
    }
    .text{
      font-size: 12px;
    }
    .findlist{
    display: flex;
    margin: 40px 0 0 10px;
    }
  
</style>